package com.app.controller;

import com.app.service.IUserService;
import com.app.utils.TokenManager;
import com.bby.CookieUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller()
public class ViewController {

    private TokenManager tokenManager;

    public ViewController(TokenManager tokenManager) {
        this.tokenManager = tokenManager;
    }

    @GetMapping("user")
    String userPage(HttpServletRequest request){
        String token=CookieUtils.getValue(request.getCookies(),"token");
        if (token==null||tokenManager.getUserId(token)==null) return "login";
        else return "user";
    }
    @GetMapping("login")
    String loginPage(HttpServletRequest request){
        String token=CookieUtils.getValue(request.getCookies(),"token");
        if (token==null||tokenManager.getUserId(token)==null) return "login";
        else return "user";
    }
    @GetMapping("register")
    String registerPage(HttpServletRequest request){
        String token=CookieUtils.getValue(request.getCookies(),"token");
        if (token==null||tokenManager.getUserId(token)==null) return "register";
        else return "user";
    }
    @GetMapping("mydisk")
    String mydiskPage(){
        return "mydisk";
    }
    @GetMapping("pubshare")
    String pubsharePage(){
        return "pubshare";
    }
}
